<%def name="fieldsets(fieldset)">
<fieldset class="module aligned ${fieldset.classes}">
  
% if fieldset.name:
<h2>${fieldset.name}</h2>
% endif

% if fieldset.description:
<div class="description">${fieldset.description}</div>
% endif

  
% for line in fieldset:

      <div class="form-row${' errors' if line.errors() else ''} ${' '.join([field.field.name for field in line])}">
      ${line.errors()}
      
% for field in line:
      <div ${'class="field-box"' if len(line.fields)!=1 else ''}>

% if field.is_checkbox:
## changed the order of checkbox and label
              <div class='formcheckboxlabel'>${field.label_tag()}
              </div>
              <div class='helpfieldblock'>
                    ${field.field}
              </div>

% elif field.is_inline:

    % for i, informset in enumerate(inline_admin_formsets):
        % if informset.opts.__class__.__name__ == field.field.name:

            <%namespace name="tabular" file="admin/edit_inline/tabular.html"/>
            <%namespace name="stacked" file="admin/edit_inline/stacked.html"/>

            % if informset.opts.template == "admin/edit_inline/tabular.html":
                ${tabular.inline_edit(informset, i)}
            % else:
                ${stacked.inline_edit(informset, i)}
            % endif

        % endif
    % endfor
         
% else:

              ${field.label_tag()}
      <div class='helpfieldblock'>
% if hasattr(field.field.field, "help_text") and field.field.field.help_text:
<p class="help">${field.field.field.help_text}</p>
% endif

% if getattr(field, 'is_readonly', False):
            <p>${field.contents()}</p>

% else:
            ${field.field}
          
% endif
      </div> <!-- class='helpinputblock' -->

% endif
          

      </div> <!-- class='fieldbox' -->
      
% endfor

      </div>
  
% endfor

</fieldset>
</%def>

